package com.wedo.mall.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.e.library.fragment.EFragment;
import com.e.library.activity.EActivity;
import com.e.library.http.EApi;
import com.e.library.http.EClient;
import com.e.library.http.EObserver;
import com.e.library.http.EResponse;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.wedo.mall.R;
import com.wedo.mall.activity.user.PurchaseRecordActivity;
import com.wedo.mall.adapter.GoodsAdapter;
import com.wedo.mall.entity.Agent;
import com.wedo.mall.entity.Goods;
import com.wedo.mall.entity.GoodsRecord;
import com.wedo.mall.ptr.Pull2Refresh;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import io.reactivex.Observable;

/**
 * A simple {@link Fragment} subclass.
 */
public class CollectionGoodsFragment extends EFragment<EActivity> {

    @BindView(R.id.tv_empty) TextView tv_empty;
    @BindView(R.id.rv_list) XRecyclerView rv_list;
    private GoodsAdapter mGoodsAdapter;

    private Pull2Refresh<Goods> ptr;

    public static CollectionGoodsFragment with(){
        return new CollectionGoodsFragment();
    }

    @Override
    protected int layout() {
        return R.layout.fragment_collection_goods;
    }

    @Override
    protected void onFragmentCreated(View contentView, Bundle bundle) {
        rv_list.setHasFixedSize(true);
        rv_list.setLayoutManager(new GridLayoutManager(this.getActivity(),2));

        ptr = new Pull2Refresh<>();

        mGoodsAdapter = new GoodsAdapter(this.getActivity(),null);
        mGoodsAdapter.isCollection(true);
        mGoodsAdapter.setOnRefreshClickListener(new GoodsAdapter.OnCollectionGoodsFragmentListener() {
            @Override
            public void onRefreshClick() {
                refresh();
            }
        });
        mGoodsAdapter.collectionGoodsListener(activity());

        ptr.widget(rv_list).adapter(mGoodsAdapter).url(EApi.USER_COLLECTGOODS).clazz(Goods.class).emptyWidget(tv_empty).done();

    }

    public void refresh(){
        ptr.refresh();
    }
}
